home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / bc_pas_1.zip / MVI.C < prev    next >
C/C++ Source or Header  |  1992-06-15  |  3KB  |  141 lines

  1. /*$Author:   BCRANE  $*/
  2. /*$Date:   15 Jun 1992 10:52:56  $*/
  3. /*$Header:   W:/sccs/pastsr/mvi.c_v   1.0   15 Jun 1992 10:52:56   BCRANE  $*/
  4. /*$Log:   W:/sccs/pastsr/mvi.c_v  $
  5.  * 
  6.  *    Rev 1.0   15 Jun 1992 10:52:56   BCRANE
  7.  * Initial revision.
  8. */
  9. /*$Logfile:   W:/sccs/pastsr/mvi.c_v  $*/
  10. /*$Modtimes$*/
  11. /*$Revision:   1.0  $*/
  12. /*$Workfile:   mvi.c  $*/
  13.  
  14.  
  15.     /*\
  16.     |*|----====< MVI.C >====----
  17.     |*|
  18.     |*| This little program sends text commands to the MVPROAS DOS
  19.     |*| device driver. After sending a command, the result is reported
  20.     |*| back to the user.
  21.     |*|
  22.     \*/
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <malloc.h>
  27.  
  28. #include <fcntl.h>
  29. #include <sys\types.h>
  30. #include <sys\stat.h>
  31. #include <io.h>
  32.  
  33.     /*\
  34.     |*| global variables
  35.     \*/
  36.  
  37.         char    buff[100],*b;
  38.         int     proas;
  39.  
  40.     /*\
  41.     |*|----====< Start of execution >====----
  42.     \*/
  43.  
  44. main(argc,argv)
  45.     int argc;
  46.     char *argv[];
  47. {
  48. int n;
  49.  
  50.     /* open the device                                                  */
  51.  
  52.         if ((proas = open ("MVPROAS",O_RDWR, S_IREAD | S_IWRITE)) == -1) {
  53.             printf ("\acannot open the MVPROAS device!\n");
  54.             exit(0);
  55.         }
  56.     /* report the starting status                                       */
  57.  
  58.         ReportStatus();
  59.  
  60.     /* if there is data on the command line, process it, else stdin     */
  61.  
  62.         if (argc > 1) {
  63.  
  64.         /* build the combined string                                    */
  65.  
  66.             n = 1;
  67.             while (n < argc ) {
  68.                 strcat (buff,argv[n++]);
  69.                 strcat (buff," ");
  70.             }
  71.             strcat (buff,"\n");
  72.  
  73.  
  74.             b = buff;
  75.             while (*b) b++;
  76.             write   (proas,buff,b-buff);
  77.             write   (proas,"\n",2);
  78.             ReportStatus();
  79.  
  80.             close (proas);
  81.             exit (0);
  82.         }
  83.  
  84.     /* get text from stdin                                              */
  85.  
  86.         while (!feof(stdin)) {
  87.  
  88.             printf (">");               // give the user a prompt
  89.             fgets (buff,100,stdin);     // get the next string
  90.             if (buff[0] == 0x0a)        // if null, exit to DOS
  91.                 break;
  92.             if (buff[0] != '?') {       // '?' is used to query the status
  93.                 b = buff;
  94.                 while (*b) b++;
  95.                 write   (proas,buff,b-buff);
  96.                 write   (proas,"\n",2);
  97.             }
  98.             ReportStatus();             // return the state
  99.         }
  100.  
  101.         close (proas);
  102.  
  103. }
  104.  
  105.  
  106.     /*\
  107.     |*|----====< ReportStatus >====----
  108.     |*|
  109.     |*| This procedure reports the current text message from MVPROAS
  110.     |*|
  111.     \*/
  112.  
  113. ReportStatus()
  114. {
  115. char text[256],*t;
  116.  
  117.     /* if busy, report it till the cows come home (10 seconds max)      */
  118.  
  119.         while (1) {
  120.             read(proas,text,256);
  121.  
  122.             t = text;
  123.             while (*t != 0x0a)
  124.                 putch (*t++);
  125.             putch (0xd);
  126.             putch (0xa);
  127.  
  128.             read(proas,text,256);
  129.             if (text[0] != 'B')
  130.                 break;
  131.         }
  132.  
  133. }
  134.  
  135.  
  136.     /*\
  137.     |*| end of MVI.C
  138.     \*/
  139.  
  140.  
  141.